/**
 * 黑魔法师先遣队副本
 * 
 */
var setupTask;

//设置多久开启一次(小时:为单位)
var starttime = 1;

//设置每次活动结束的时间(分钟:为单位)
var overtime = 10;

//设置每次副本开启的分钟段(分钟:为单位)
var startminute = 05;

var mapList = Array(
270030630,
211042200,
240040512,
211080600,
221030660,
220060400,
220070400);

//开始地图
var mapId = mapList[Math.floor(Math.random() * mapList.length)];

//怪物列表
var mobList = Array(
9303133, 
9303134,
9303135,
9303136,
9303137);


var mobId = mobList[Math.floor(Math.random() * mobList.length)];

//boss的x坐标
var boosxPoint;
//boss的y左边
var boosyPoint;

//坐标
var xyPoint;
//地图名称
var mapname;

switch (mapId) {
case 270030630:
	mapname = "[时间之路]另一个忘却之路4";
	boosxPoint = 201;
	boosyPoint = -523;
	break;
case 211042200:
	mapname = "[神秘岛]艰苦洞穴3";
	boosxPoint = 266;
	boosyPoint = -453;
	break;
case 240040512:
	mapname = "[米纳尔森林]被遗忘的龙之巢穴2";
	boosxPoint = 179;
	boosyPoint = 774;
	break;
case 211080600:
	mapname = "[玫瑰庭院]秘密庭院3";
	boosxPoint = 1684;
	boosyPoint = -200;
	break;
case 221030660:
	mapname = "[UFO内部]通道H03";
	boosxPoint = 409;
	boosyPoint = 0;
	break;
case 220060400:
	mapname = "[玩具城]怪异的回廊";
	boosxPoint = -689;
	boosyPoint = -303;
	break;
case 220070400:
	mapname = "[玩具城]消失的回廊";
	boosxPoint = -450;
	boosyPoint = -775;
	break;
}

function init() {
	scheduleNew();
}


function scheduleNew() {
	var cal = java.util.Calendar.getInstance();
	var hour = cal.get(java.util.Calendar.HOUR_OF_DAY); //获得小时 24小时制
	var minute = cal.get(java.util.Calendar.MINUTE); //获得分钟
	var second = cal.get(java.util.Calendar.SECOND); //获得秒
	cal.set(java.util.Calendar.HOUR, 0); //设定的小时 12小时制
	cal.set(java.util.Calendar.MINUTE, startminute); //设定的分钟
	cal.set(java.util.Calendar.SECOND, 0); //设定的秒钟
	var nextTime = cal.getTimeInMillis();
	while (nextTime <= java.lang.System.currentTimeMillis()) {
		nextTime += 1000 * 60 * 60 * starttime; //设置多久开启
	}
	setupTask = em.scheduleAtTimestamp("startEvent", nextTime);
}

function startEvent() {
	var cal = java.util.Calendar.getInstance();
	var hour = cal.get(java.util.Calendar.HOUR_OF_DAY); //获得小时  24小时制
	var minute = cal.get(java.util.Calendar.MINUTE); //获得分钟
	var second = cal.get(java.util.Calendar.SECOND); //获得秒
	cal.set(java.util.Calendar.HOUR, 0); //设定的小时 12小时制
	cal.set(java.util.Calendar.MINUTE, startminute); //设定的分钟
	cal.set(java.util.Calendar.SECOND, 0); //设定的秒钟
	var nextTime = cal.getTimeInMillis();
	while (nextTime <= java.lang.System.currentTimeMillis()) {
		nextTime += 1000 * 60 * overtime; //设置多久结束
	}
	setupTask = em.scheduleAtTimestamp("finishEvent", nextTime);

	
	var eim = em.newInstance("MonsterBOSS");
	var map = eim.setInstanceMap(mapId);
	map.resetFully();
	eim.getMapFactory().getMap(mapId).killAllMonsters(false);

	var mob = em.getMonster(mobId);
	var overrideStats = em.newMonsterStats();
	var hprand = 10000000; //设置600E血
	overrideStats.setOHp(hprand);
	overrideStats.setOExp(500000);
	overrideStats.setOMp(200000);
	mob.setOverrideStats(overrideStats);
	mob.setHp(hprand);
	eim.registerMonster(mob);
	map.spawnMonsterOnGroundBelow(mob, new java.awt.Point(boosxPoint, boosyPoint));

	em.broadcastServerMsg(5120173, "黑魔法师的先遣队在[" + mapname + "]大肆破坏.", true);//布莱克宾漂浮特效
	em.broadcastServerMsg("黑魔法师的先遣队在[" + mapname + "]大肆破坏.扫荡时间15分钟请玩家们快去消灭他们！");
}


function finishEvent() {
	//em.broadcastServerMsg("黑魔法师的先遣队在.每个时间段的3分钟-33分钟分进攻城市，每隔" + starttime + "小时开放一次！每次进攻城市将会持续" + overtime + "分钟");
	scheduleNew();
}

function cancelSchedule() {
	if (setupTask != null) {
		setupTask.cancel(true);
	}
}
